package de.dhbw.karlsruhe.picsim.model.commands.impl;

import de.dhbw.karlsruhe.picsim.model.actions.ActionFactory;
import de.dhbw.karlsruhe.picsim.model.actions.PicAction;
import de.dhbw.karlsruhe.picsim.model.memory.RegisterValue;
import de.dhbw.karlsruhe.picsim.model.memory.impl.RegisterValueImpl;
import de.dhbw.karlsruhe.picsim.util.Bits;
import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: user
 * Date: May 3, 2010
 * Time: 1:40:36 AM
 */
public final class RotateLeft extends RotateSupport {
    public RotateLeft(final boolean targetIsWRegister, @NotNull final Bits argument) {
        super(targetIsWRegister, argument);
    }

    @NotNull
    @Override
    protected RegisterValue doRotate(@NotNull final RegisterValue addressedFile,
                                     @NotNull final List<PicAction> yourActions,
                                     @NotNull final ActionFactory actionFactory, final boolean carryFlag) {
        if (addressedFile.isSet(7)) {
            yourActions.add(actionFactory.setCarryBit());
        } else {
            yourActions.add(actionFactory.clearCarryBit());
        }
        int result = addressedFile.asInteger() << 1;
        if (carryFlag) {
            result += 1;
        }
        return RegisterValueImpl.createUnsafe(result);

    }
}
